package com.buaa.aimall.computeModule.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buaa.aimall.Utils.PageReturnResult;
import com.buaa.aimall.computeModule.Entity.ComputeResourceEntity;
import com.buaa.aimall.computeModule.Mapper.ComputeResourceMapper;
import org.springframework.stereotype.Service;

@Service
public class ComputeResourceServiceImpl extends ServiceImpl<ComputeResourceMapper, ComputeResourceEntity> implements ComputeResourceService {
    public PageReturnResult<ComputeResourceEntity> getByOwner(IPage<ComputeResourceEntity> page, String ownerId) {
        PageReturnResult<ComputeResourceEntity> result = new PageReturnResult<>();
        LambdaQueryWrapper<ComputeResourceEntity> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(ComputeResourceEntity::getOwner, ownerId);
        queryWrapper.orderByDesc(ComputeResourceEntity::getCreateTime);

        result.setRecords(this.page(page, queryWrapper).getRecords());
        result.setTotalCount(this.count(queryWrapper));
        return result;
    }
}
